package display;

import paihang.Rank;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.sql.ResultSet;

public class RankFrame extends JFrame {
    public String[][] ranks = new String[20][2];

    public void run(){
        JPanel panel = new JPanel();/*创建一个容器*/
        panel.setSize(300,400);
        panel.setBackground(new Color(201, 226, 252));
        panel.setOpaque(true);

        ResultSet rs=Rank.search();
        try {
            ranks[0][0]="排名";
            ranks[0][1]="用时";
            int i=0;
            while (rs.next()) {

                i++;
                ranks[i][1]=rs.getDouble(1)+"秒";
                ranks[i][0]=String.valueOf(i);
            }
        }
        catch (Exception e){
            System.out.println(e);
        }





        String[] columnNames = new String[] { "rank", "time"};
        // 表格中的内容，是一个二维数组

        JTable t = new JTable(ranks,columnNames);

        t.setFont(new Font("微软雅黑", Font.PLAIN + Font.BOLD, 16));
        t.setSize(300,800);
        panel.add(t);
        this.add(panel);

    }
 public  RankFrame() {
        /*设置图标*/
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("排行榜");
        this.setSize(300, 400);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setFont(new Font("微软雅黑", Font.PLAIN + Font.BOLD, 20));



    }
}
